<template>
  <el-container>
    <!-- 头部区域 -->
    <el-header>
      <div class="header-info">
        <img src="~assets/image/me.png" alt="">
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="loginout">退出</el-button>
    </el-header>
    <!-- 主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="iscollapse ? '64px' : '280px'">
        <el-menu
          :unique-opened="true"
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409EFF"
          :collapse="iscollapse"
          :collapse-transition="false"
          :router="true">
          <!-- 一级菜单 -->
          <el-submenu  :index="String(item.id)" v-for="(item, index) in menuList" :key="item.id" >
            <!-- 一级菜单模板区 -->
            <template slot="title">
              <!-- 图标 -->
              <i :class="elIcon[index]"></i>
              <!-- 文本 -->
              <span>{{ item.authName }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item :index="'/home/' + citem.path" v-for="citem in item.children" :key="citem.id">
              <i class="el-icon-menu"></i>
              <!-- 文本 -->
              <span>{{ citem.authName }}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <div v-show="!iscollapse" class="togger-btn btn1" @click="toggerBtn1">></div>
      <div v-show="iscollapse" class="togger-btn btn2" @click="toggerBtn2">></div>
      <!-- 内容 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>

import { getMenuList } from 'network/menu'

export default {
  name: "Home",
  components: {
    
  },
  created() {
    this.getMenuList()
  },
  data() {
    return {
      menuList: [],
      elIcon: ['el-icon-user', 'el-icon-coin' , 'el-icon-s-goods', 'el-icon-s-order', 'el-icon-s-marketing'],
      iscollapse: false
    }
  },
  methods: {
    loginout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    async getMenuList() {
      const { data: menuData, meta: message} = await getMenuList()
      if(message.status !== 200) return this.$message.error(message.msg)
      this.menuList = menuData
      // console.log(this.menuList);
    },
    toggerBtn1() {
      this.iscollapse = true
    },
    toggerBtn2() {
      this.iscollapse = false
    }
  }
}
</script>

<style>
  .el-container {
    height: 100%;
  }

  .el-header {
    background-color: #373D41;
    display: flex;
    justify-content: space-between;
  }

  .header-info img {
    width: 50px;
    border-radius: 50%;
    vertical-align: middle;
  }

  .header-info span {
    padding-left: 20px;
    vertical-align: middle;
    font-size: 20px;
    color: #fff;
  }

  .el-aside {
    background-color: #373D41;
  }

  .el-menu {
    border-right: none;
  }

  .togger-btn {
    width: 20px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    background-color: #333744;
    color: #fff;
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
  }

  .btn1 {
    position: absolute;
    left: 280px;
    top: 350px;
  }

  .btn2 {
    position: absolute;
    left: 64px;
    top: 350px;
  }
</style>